/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * Licensed under Simplified BSD License
 *
 *
 * @author: jin Chen 
 * @date: Dec 16, 2005$
 * @version: 1.0
 */
package edu.psu.geovista.app.gmatrix.app;

import edu.psu.geovista.app.gmatrix.JDfMatrix;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashSet;

public class SimpleSortableMatrix  extends JDfMatrix {
        public SimpleSortableMatrix() {
        }

        public SimpleSortableMatrix(int columnHeaderHight, int rowHeaderWidth) {
            super(rowHeaderWidth, columnHeaderHight);
            JPanel bp = this.getButtonPanel();
            this.add(bp, BorderLayout.SOUTH );
        }

        private JPanel getButtonPanel(){
            final SimpleSortableMatrix matrix=this;
             JButton rmv =new JButton("delete");  //delete select
                     rmv.addActionListener(new ActionListener(){
                             public void actionPerformed(ActionEvent e){
                                 int[] select = matrix.getSelectedRows() ;
                                 matrix.removeRows(select);
                             }
                     });
             JButton rmvall =new JButton("delte all");
                     rmvall.addActionListener(new ActionListener(){
                             public void actionPerformed(ActionEvent e){
                                 int nbrow = matrix.getNumOfRow();
                                 int all[]=new int[nbrow];
                                 for (int i=0;i<all.length ;i++){
                                     all[i]=i;
                                 }
                                 matrix.removeRows(all);
                                 matrix.select(new HashSet<Point>() );   //clear all
                             }
                     });



          JButton mvup =new JButton("Up");
                     mvup.addActionListener(new ActionListener(){
                             public void actionPerformed(ActionEvent e){
                                // Color[][] colors = get2RowColor(matrix );
                                 matrix.moveRowUp();
                             }
                     });
          JButton mvdn =new JButton("Down");
                     mvdn.addActionListener(new ActionListener(){
                             public void actionPerformed(ActionEvent e){
                                 int nbrow = matrix.getNumOfRow();
                                 int[] rows=new int[]{nbrow-1,nbrow-2};
                                 matrix.moveRowsDown();
                             }
                     });



        JPanel sp=new JPanel();
         JPanel btnp=new JPanel();
         btnp.add(rmv);
         btnp.add(rmvall);

         btnp.add(mvup);
         btnp.add(mvdn);
          return btnp;
        }

}
